package irio.pythcal;

import java.lang.Math;


public class Vec {
	public float x,y,z;

	public Vec() {
		this.x = 0;
		this.y = 0;
		this.z = 0;
	}

	
	public Vec(final float x) {
		this.x = x;
		this.y = x;
		this.z = x;
	}
	
	public float getRad() {
		Complex c = new Complex(x,y);
		return (float)c.phase();
	}
	
	public Vec(final float x, final float y, final float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public void set(final float x, final float y, final float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	public void set(final Vec o) {
		this.x = o.x;
		this.y = o.y;
		this.z = o.z;
	}
	
	public Vec cross(final Vec o) {
		return new Vec(o.y*z - o.z*y, o.z*x - o.x*z, o.x*y - o.y*x);
		
	}

	public float dot(final Vec o) {
		return x*o.x + y*o.y + z*o.z;
	}
	public Vec add(final Vec o) {
		return new Vec(x+o.x, y+o.y, z+o.z);
	}

	public void addDirect(final Vec o) {
		x+=o.x;
		y+=o.y;
		z+=o.z;
	}
	public void subDirect(final Vec o) {
		x+=o.x;
		y+=o.y;
		z+=o.z;
	}

	public Vec sub(final Vec o) {
		return new Vec(x-o.x, y-o.y, z-o.z);
	}

	public Vec mul(final float f) {
		return new Vec(x*f, y*f, z*f);
	}

	public void mulDirect(final float f) {
		x*=f;
		y*=f;
		z*=f;
	}

	
	public Vec norm() {
		return new Vec(x,y,z).mul(1.0f/len());
	}

	public void normDirect() {
		float l = len();
		if (l==0.0) l=1.0f;
		x/=l;
		y/=l;
		z/=l;
	}

	
	public float len() {
		return (float)Math.sqrt(x*x + y*y + z*z);
	}

	Vec glMatMul(float[] pm) {
	       
	      Vec res = new Vec(0,0,0);
	       
	      res.x = pm[0] * x + 
	              pm[1] * y +       
	              pm[2] * z;  

	      res.y = pm[4] * x + 
	              pm[5] * y +       
	              pm[6] * z;       

	      res.z = pm[8] * x + 
	              pm[9] * y +       
	              pm[10] * z;       
	      return res;
	}
}
